package com.anlu.concurrent.ch1;

import java.util.concurrent.ExecutionException;

/**
 * 守护线程的使用
 */
public class DaemonThread {
    private static class UseThread extends Thread{
        @Override
        public void run() {
            try{
                while (!isInterrupted()){
                    System.out.println(Thread.currentThread().getName()+"  I am  extends Thread");
                }
                System.out.println(Thread.currentThread().getName()+" interrupt flag is "+interrupted());
            }finally {
                System.out.println("..... finally");
            }
        }
    }

    public static void main(String[] args)throws InterruptedException, ExecutionException {
        UseThread useThread = new UseThread();
        useThread.setDaemon(true);
        useThread.start();
        Thread.sleep(5);
        useThread.interrupt();
    }


}
